#configure variables
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
# 如果单独编译这个模块，请打开下面一行


set(VERSION_INFO "0.0.0.1")
set(TARGET_NAME "ZLMediaEngine")

project(${TARGET_NAME} VERSION ${VERSION_INFO})  
set(${CMAKE_PROJECT_NAME} ${TARGET_NAME})
message(${CMAKE_PROJECT_NAME})

if(MSVC)
    set(MY_VERSIONINFO_RC "${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.rc")
    configure_file("${CMAKE_CURRENT_SOURCE_DIR}/VersionInfo.rc.in" "${MY_VERSIONINFO_RC}")
else()
	set(MY_VERSIONINFO_RC "")
endif()


if(WIN32)
# 设置二进制可执行文件输出路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
# 设置库文件输出路径
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
endif()


#set_property(GLOBAL PROPERTY USE_FOLDERS On)

#add_compile_options("/Ob2")
#add_compile_options(-std=c++14)



add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DNOMINMAX)
add_definitions(-DWEBRTC_USE_H264)


if(WIN32)
	set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

	add_definitions(-DWIN32_LEAN_AND_MEAN)
	add_definitions(-DWEBRTC_WIN)
	message("Windowds  .....")
	#add_definitions("-Wall -g -fPIC -Ob2")
else()

	message("linux .....")
	add_definitions(-DWEBRTC_POSIX)
	add_definitions(-DWEBRTC_LINUX)
	add_definitions("-Wall -g -fPIC -O3")
if(ANDROID)
	add_definitions(-DWEBRTC_ANDROID)
	set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -s -fPIC" )
	set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -s -fPIC" )
	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}  -Wall -s -fPIC")
	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -s -fPIC")
endif()
	
endif()


include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/utility")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/mongoose/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/httpserver/")

#设置子目录
#"src/IoModule/Utility"
set(SUB_DIR_LIST 
"./src/utility/" 
"./src/mongoose/" 
"./src/websocket/" 


)


if(WIN32)
#list(APPEND SUB_DIR_LIST "../webrtc/rtc_base/win")
endif()


#设置子目录

foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文件
	include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR})

endforeach()
foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文件
    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
	
	file(GLOB SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.c")
	file(GLOB INC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.h")

	source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
	list(APPEND SRC_FILE_LIST ${SRC_FILES})
	list(APPEND INC_FILE_LIST ${INC_FILES})
	
	#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR})

endforeach()
if(WIN32)
foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文件
    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
	
	#file(GLOB SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.cxx")
	#source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
	#list(APPEND SRC_FILE_LIST ${SRC_FILES})
endforeach()


else()

foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文件
    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
	
	#file(GLOB SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.cpp")
	#source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
	#list(APPEND SRC_FILE_LIST ${SRC_FILES})
	
endforeach()

endif()



# 追加android jni 代码
if(ANDROID)
set(SUB_DIR_LIST  "./src/jni")

foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文件
    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
	
	file(GLOB SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.cpp")
	file(GLOB INC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.h")

	source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
	
	list(APPEND SRC_FILE_LIST ${SRC_FILES})
	list(APPEND INC_FILE_LIST ${INC_FILES})

endforeach()

endif()


# 生成myProject_shared动态库文件
##add_library(webrtcshare SHARED ${SRC_FILE_LIST}  ${INC_FILE_LIST})

#set(other_cpp "${CMAKE_CURRENT_SOURCE_DIR}/../../IoModule/Utility/Utility.cpp")

add_library(${TARGET_NAME} SHARED ${SRC_FILE_LIST}  ${INC_FILE_LIST} ${MY_VERSIONINFO_RC})

 #pragma comment (lib, "ws2_32.lib")
if(WIN32)
target_link_libraries(${TARGET_NAME} ws2_32.lib winmm.lib)
else()
	if(ANDROID)
	else()
		set_target_properties(${TARGET_NAME}  PROPERTIES VERSION ${VERSION_INFO} SOVERSION 1)
	endif()
endif()
#
if(ANDROID)
target_link_libraries(${TARGET_NAME} log)
#set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${CMAKE_PROJECT_NAME}")

endif()

#message("Windowds  .....webrtcshare PROJECT_BINARY_DIR " ${PROJECT_BINARY_DIR})
#message("Windowds  .....webrtcshare CMAKE_PROJECT_NAME " ${CMAKE_PROJECT_NAME})
#message("Windowds  .....webrtcshare TARGET_NAME " ${TARGET_NAME})
#message("Windowds  .....webrtcshare PROJECT_SOURCE_DIR " ${PROJECT_SOURCE_DIR})
#message("Windowds  .....webrtcshare CMAKE_CURRENT_SOURCE_DIR " ${CMAKE_CURRENT_SOURCE_DIR}) # 当前路径cmakelist.txt 的路径

#target_link_libraries(${TARGET_NAME}  VideoJxred)

add_subdirectory(example)